#-------------------------------------------------------------------------------
# Name:        HUD
# Purpose:
#
# Author:      Pablo
#
# Created:     28/04/2013
# Copyright:   (c) Monxcleyr Productions 2013
# Licence:     GPL v3
#-------------------------------------------------------------------------------
#!/usr/bin/env python

import pygame
from ..gui import label

class Hud():

  """class comment"""

  def __init__(self, surface):
    self.popup1 = pygame.image.load('resources/graphics/hud/popup1.bmp')
    self.popup1.set_colorkey((255,0,255))
    self.font = pygame.font.Font('resources/fonts/system.ttf', 15)
    self.pos = (12, 400)
    self.surface = surface
    self.textlist = []
    self.line1 = label.Label(self.surface, 'Test setence for the dialog display system. Lines can be sooo long :O', (60, 460), 'left', self.font, (0, 0, 0))
    self.line2 = label.Label(self.surface, 'Test setence for the dialog display system', (60, 480), 'left', self.font, (0, 0, 0))
    self.line3 = label.Label(self.surface, 'Test setence for the dialog display system', (60, 500), 'left', self.font, (0, 0, 0))
    self.line4 = label.Label(self.surface, 'Test setence for the dialog display system', (60, 520), 'left', self.font, (0, 0, 0))
    self.count = 0
    self.drawnow = False


  def draw(self, canTick, keyPressed):

    if len(self.textlist) == 0:
      canTick = True
      self.drawnow = False
      return True
    else:
      canTick = False
    if len(self.textlist) >= 1:
      self.line1.setText(self.textlist[0])
    else:
      self.line1.setText(' ')
    if len(self.textlist) >= 2:
      self.line2.setText(self.textlist[1])
    else:
      self.line2.setText(' ')
    if len(self.textlist) >= 3:
      self.line3.setText(self.textlist[2])
    else:
      self.line3.setText(' ')
    if len(self.textlist) >= 4:
      self.line4.setText(self.textlist[3])
    else:
      self.line4.setText(' ')

    self.surface.blit(self.popup1, self.pos)
    self.line1.draw()
    self.line2.draw()
    self.line3.draw()
    self.line4.draw()

    key = pygame.key.get_pressed()

##    if self.count> 4:
##      if key[pygame.K_RETURN]:
    if keyPressed['RETURN'] == True or keyPressed['SPACE']:
      if len(self.textlist) > 4:
        self.textlist.pop(0)
        self.textlist.pop(0)
        self.textlist.pop(0)
        self.textlist.pop(0)
      elif len(self.textlist) > 3:
        self.textlist.pop(0)
        self.textlist.pop(0)
        self.textlist.pop(0)
        self.textlist.pop(0)
      elif len(self.textlist) > 2:
        self.textlist.pop(0)
        self.textlist.pop(0)
        self.textlist.pop(0)
      elif len(self.textlist) > 1:
        self.textlist.pop(0)
        self.textlist.pop(0)
      elif len(self.textlist) > 0:
        self.textlist.pop(0)
      self.count = 0


    self.count += 1
    return canTick


  def setText(self, textlist):
    self.textlist = textlist
    self.drawnow = True

  def resetText(self):
    self.textlist = []


